import _ from "underscore-contrib";

export const isAuthenticated = (state) => {
  return state.auth != null && state.auth.access_token_expiration != null && new Date(state.auth.access_token_expiration) > new Date();
};

export const isInRole = (state, getters) => (role) => {
  if (!state.auth || !state.auth.roles) return false;

  const existed = _.intersection(state.auth.roles, role).length > 0;
  const result = state.auth != null && getters.isAuthenticated && state.auth.roles != null && existed;
  return result;
};

export const layout = (state, getters) => {
  return state.layout;
};
export const navPos = (state, getters) => {
  return state.layout.navPos;
};
export const toolbar = (state, getters) => {
  return state.layout.toolbar;
};
export const footer = (state, getters) => {
  return state.layout.footer;
};
export const boxed = (state, getters) => {
  return state.layout.boxed;
};
export const roundedCorners = (state, getters) => {
  return state.layout.roundedCorners;
};
export const viewAnimation = (state, getters) => {
  return state.layout.viewAnimation;
};

export const splashScreen = (state, getters) => {
  return state.splashScreen;
};
